﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;

namespace Tomahawk.Runtime.Resources
{
    /// <summary>
    /// This base class defines the common mehotds for loadable resource types
    /// </summary>
    public abstract class LoadableResource : ILoadableResource
    {
        /// <summary>
        /// Constructor.
        /// When a new resource is created, ir must register itself in the manager
        /// </summary>
        public LoadableResource()
        {
            Engine.Instance.ResourceManager.registerResource(this);
        }

        /// <summary>
        /// Load the resource from content pipeline 
        /// </summary>
        public void LoadContents(GraphicsDevice graphics, ContentManager contentManager)
        {
            this.isReady = this.OnLoad(graphics, contentManager);
        }

        /// <summary>
        /// Provide this method in the derived type to perform the custom loading of the assets
        /// </summary>
        protected abstract bool OnLoad(GraphicsDevice graphics, ContentManager contentManager);

        /// <summary>
        /// Flag to store the readyness of the resource
        /// </summary>
        private bool isReady = false;

        /// <summary>
        /// Returns true when the resource had been correctly loaded
        /// </summary>
        public bool IsReady
        {
            get { return this.isReady; }
        }

     }

}
